package com.demo.java.concurrent.threadpool;

import com.demo.java.utils.ThreadUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class CompletableFutureTest {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);

        final ExecutorService executorService = Executors.newFixedThreadPool(1);
        final ExecutorService executorService1 = Executors.newSingleThreadExecutor();
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            log.info("start, {}", ThreadUtils.threadName());
            ThreadUtils.sleep(5, TimeUnit.SECONDS);
            log.info("end, {}", ThreadUtils.threadName());
            latch.countDown();
            return "complate task";
        }, executorService);
        log.info("main1, {}", ThreadUtils.threadName());
        future.thenAccept(System.out::println);
        log.info("main2, {}", ThreadUtils.threadName());
        latch.await();
    }
}
